# ======================================================================
#
# Copyright (C) ADN
# ADN::SERVER::Header
# Description:
#  - Creation des Headers
#  - Creation of the Headers
#
# ======================================================================

package ADN::SERVER::Header;

use strict;
use POSIX qw(strftime);

sub new {
	  my $self = shift;
	  my $class = ref($self) || $self;
	  return $self if ref $self;
	  $self = bless {} => $class;
    return $self;
}

# #######################
# CREATE HEADER
# #######################
sub start 
{
		my $self = shift;
		%{$self->{param}} = @_;
    my $header;
    if ( $self->{param}{Nb} == 200 ) {
	   $header = 'HTTP/1.1 '. $self->{param}{Nb} ." OK\r\n";
    }
    if ( $self->{param}{Nb} == 202 ) {
	   $header = 'HTTP/1.1 '. $self->{param}{Nb} ." Accepted\r\n";
    }
    $header .= 'Content-Length: ' . $self->my_length() . "\r\n";
    $header .= 'Content-Type: text/' . $self->{param}{Type} . "; charset=utf-8\r\n";
    $header .= "Server: ADN HTTP-API/0.6\r\n";
    $header .= 'Date : ' . my_date() . "\r\n";
    $header .= "Connection: close\r\n";
    $header .= $self->{param}{Data};
    $header .= "\r\n\r\n";
    return $header;
}

# #######################
# LENGHT DATA IN HEADER
# #######################
sub my_length {
		my $self = shift;
    return length $self->{param}{Data};
}

# #######################
# DATE THE HEADER
# #######################
sub my_date {
    return strftime "%a, %d %b %Y %H:%M:%S ", localtime;
}

# #######################
# DESTROY OBJECT
# #######################
sub DESTROY {
    my $self = shift;
    return;
}
1;
__END__
